// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   CourseScheduleService.java

package com.nervytech.tutorcruise.db.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.nervytech.tutorcruise.course.beans.CourseDetailsBean;
import com.nervytech.tutorcruise.course.beans.CourseSearchResultBean;
import com.nervytech.tutorcruise.db.dao.interfaces.ICourseScheduleDAO;
import com.nervytech.tutorcruise.db.dao.model.CourseSchedule;
import com.nervytech.tutorcruise.db.service.interfaces.ICourseScheduleService;
import com.nervytech.tutorcruise.service.exception.TrainerCruiseServiceException;

@Service("courseScheduleService")
public class CourseScheduleService implements ICourseScheduleService {

	@Autowired
	private ICourseScheduleDAO courseScheduleDAO;

	public void saveSchedule(CourseSchedule courseSchedule)
			throws TrainerCruiseServiceException {
		try {
			courseScheduleDAO.saveCourseOverview(courseSchedule);
		} catch (Exception e) {
			e.printStackTrace();
			throw new TrainerCruiseServiceException(e.getMessage());
		}
	}

	public void updateTinyUrl(long userId, long courseId,
			long courseScheduleId, String shortUrl)
			throws TrainerCruiseServiceException {
		try {
			courseScheduleDAO.saveCourseOverview(userId, courseId,
					courseScheduleId, shortUrl);
		} catch (Exception e) {
			throw new TrainerCruiseServiceException(e.getMessage());
		}
	}

	public CourseDetailsBean getCourseDetails(long courseId)
			throws TrainerCruiseServiceException {
		CourseDetailsBean courseDetailsBean = null;
		List<CourseDetailsBean> courseDetailsList = null;
		try {
			courseDetailsList = courseScheduleDAO.getCourseDetails(courseId);
			if (courseDetailsList.size() > 0) {
				courseDetailsBean = courseDetailsList.get(0);
			}
		} catch (Exception e) {
			e.printStackTrace();
			throw new TrainerCruiseServiceException(e.getMessage());
		}
		return courseDetailsBean;
	}

	public List<CourseSearchResultBean> getScheduledCourses(long userId,
			Date date) throws TrainerCruiseServiceException {
		List<CourseSearchResultBean> courseDetailsList = null;
		try {
			courseDetailsList = courseScheduleDAO
					.getCourseDetails(userId, date);
		} catch (Exception e) {
			e.printStackTrace();
			throw new TrainerCruiseServiceException(e.getMessage());
		}
		return courseDetailsList;
	}

}